<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>助力耶微信公众平台</title>

    <link rel="stylesheet" href="style/css/layui/layui.css">
    <link rel="stylesheet" href="/style/css/login/login.css">
    <link rel="stylesheet" href="/style/css/public/tab.css">

    <script src="/style/js/jquery-3.2.1.min.js"></script>
    <script src="/style/js/layui/layui.js"></script>
    <script src="/style/js/public/tab.js"></script>
    <script src="/style/js/cookie.js"></script>
    <link rel="Shortcut Icon" href="/style/images/login/logo.png">

    <script>
        var ua = navigator.userAgent;
        var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
            isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
            isAndroid = ua.match(/(Android)\s+([\d.]+)/),
            isMobile = isIphone || isAndroid;
        //判断
        // if (isMobile) {
        //     window.location.href = '/#.html';
        //     // window.location.href = '/weXin/PC/daiLiShangPingTai/daiLiShangZongKong.html'
        // } else {
        // }
    </script>
</head>
<body>
<div class="bg"></div>
<div class=body>

    <div class="login" id="login">

        <div id="login-left">
            <div class="tabbox">
                <div class="tab">
                    <a href="javascript:;" class="on" style="margin-left: 35px">密码登录</a>
<!--                    <a href="javascript:;">验证码登陆</a>-->
                </div>
                <div class="content">
                    <ul>
                        <li>
                            <!-- 手机密码登录的表单 -->
                            <form class="layui-form" id="login-email-phone-form" method="post">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" name="username" lay-verify="required|phone"
                                                   autocomplete="off"
                                                   class="layui-input" placeholder="请输入常用手机号"
                                                   id="username">
                                        </div>
                                        <br>
                                        <span id="error-phone-email">请输入已验证的手机号</span>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="password" name="password" lay-verify="email" autocomplete="off"
                                                   class="layui-input" placeholder="请输入密码" id="password">
                                        </div>
                                        <br>
                                        <span id="error-password">请输入密码</span>
                                    </div>
                                </div>
<!--                                <a href="repwd.html" onclick="forgetPassword()" class='forgetpassword'>忘记密码?修改密码</a><br>-->
                                <button type="button" class="layui-btn" onclick="PhoneLogin()">登录</button>
                            </form>
                        </li>
                        <li>
                            <!-- 手机验证码登录的表单 -->
                            <form class="layui-form" id="login-phone-form" method="post">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="tel" name="username" lay-verify="required|phone"
                                                   autocomplete="off"
                                                   class="layui-input" placeholder="请输入已验证手机" id="userphone">
                                        </div>
                                        <br>
                                        <span id="error-phone">请输入已验证手机</span>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" name="password" autocomplete="off"
                                                   placeholder="请输入验证码" id="verification">
                                        </div>
                                        <input id="phone-code-login" type="button" value="获取验证码"
                                               onclick="loginPhoneCode()"><br>
                                        <span id="error-phone-verification">请输入4位数字验证码</span>
                                    </div>
                                </div>
<!--                                <a href="repwd.html" class="forgetpassword">忘记密码?修改密码</a><br>-->
                                <button type="button" class="layui-btn" onclick="return PhoneYZMLogin()">登录</button>
                            </form>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div id="login-right">
            <h5>请扫描微信二维码登录:</h5>
        </div>
    </div>
</div>
<script >

    /**
     * 用户密码登陆的方法
     * @return {boolean}
     * */
    function PhoneLogin() {
        console.log("111111")
        //window.location.href="http://localhost:8035/index.html"
        //用户是否点击登录的标识变量
        var username = $('#username').val();
        console.log(username);
        var password = $('#password').val();
        console.log(password);
        if (username === null || username === "") {
            if (password === null || password === "") {
                $('#error-phone-email').show();
                $('#error-password').show();
                return false;
            } else {
                $('#error-phone-email').show();
                return false;
            }
        } else {
            if (password === null || password === "") {
                $('#error-password').show();
                return false;
            }
        }
        $.ajax({
            url: '/login/keHuUserLogin',
            type: 'POST',
            data: {
                "username": username,
                "password": password
            },
            dataType: 'json',
            success: function (data) {
                layui.use(['layer'], function () {
                    console.log(data.code)
                    let layer = layui.layer;
                    if (data.code === 200) {
                        layer.msg("登录成功", {icon: 6});
                        setTimeout(function () {
                            window.location.href = 'index.html';
                        }, 500);
                    }
                    if (data.code === 500 || data.code === undefined) {
                        layer.msg("账号或密码有误", {icon: 5});
                    }
                });
            }
        });

    }

    //验证码登录
    function PhoneYZMLogin() {
        //用户是否点击登录的标识变量
        var phone = $('#userphone').val();
        //获取验证码，YZM：验证码
        var YZM = $('#verification').val();
        if (phone === null || phone === "") {
            if (YZM === null || YZM === "") {
                $('#error-phone-email').show();
                $('#error-phone-verification').show();
                return false;
            } else {
                $('#error-phone-email').show();
                return false;
            }
        } else {
            if (YZM === null || YZM === "") {
                $('#error-phone-verification').show();
                return false;
            }
        }
        $.ajax({
            url: '/login/yanZhengMaLogin',
            type: 'POST',
            data: {"keHuUsePhone": phone, "YZM": YZM},
            dataType: 'json',
            success: function (data) {
                layui.use(['layer'], function () {
                    console.log(data)
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 6});
                        window.location.href = '../../../index.html';
                    }
                    if (data.code === 500) {
                        layer.msg("登陆失败：" + data.msg, {icon: 5});
                    }
                });
            }
        });
    }

    /*
    * 获取手机验证码的方法
    * */
    function loginPhoneCode() {
        layui.use("layer", function () {
            let layer = layui.layer;
            //layer.msg("已点击，请勿连续点击");
            var phone = $('#userphone').val();
            var phoneReg = /^1[3456789]\d{9}$/;
            if (phone == null || phone === "") {
                $('#error-phone').show();
                return false;
            } else if (!phoneReg.test(phone)) {
                layer.msg("手机号必须为11位数字");
                return false;
            }
            console.log("phone")
            console.log(phone)
            $.post("/login/yanZhengMa", {"keHuUsePhone": phone}, function (data) {
                console.log("----------------------"+data.code)
                if (data.code === 200) {
                    layer.msg("已发送")
                    $('#phone-code-login').val("     已发送");
                    $('#phone-code-login').attr('disabled', true);
                    $('#phone-code-login').css('color', 'gray');
                } else if (data.code === 500) {
                    layer.msg(data.msg);
                }
            });
        });
    }

    if (window.parent != window) {
        window.parent.location.reload(true);
    }

</script>
</body>
</html>